﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DeviceInfoManage.DataAccessLayer;

namespace DeviceInfoManage.BusinessLogicLayer
{
    /// <summary>
    ///DailyItem 的摘要说明
    /// </summary>
    public class DailyItem
    {
        #region 字段属性
        private int _id;
        private string _iid;
        private string _datepart;
        private string _devicetype;
        /// <summary>
        /// ID
        /// </summary>
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 巡检ID
        /// </summary>
        public string IiD
        {
            set { _iid = value; }
            get { return _iid; }
        }
        /// <summary>
        /// 时间段
        /// </summary>
        public string DatePart
        {
            set { _datepart = value; }
            get { return _datepart; }
        }
        /// <summary>
        /// 巡检项目
        /// </summary>
        public string DeviceType
        {
            set { _devicetype = value; }
            get { return _devicetype; }
        }
        #endregion

        #region 构造函数
        public DailyItem()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        #endregion

        #region  成员方法

        /// <summary>
        ///  增加一条数据
        /// </summary>
        public void WriteItem(string[] strArr)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@IiD", SqlDbType.VarChar,50),
					new SqlParameter("@DatePart", SqlDbType.VarChar,1000),
					new SqlParameter("@DeviceType", SqlDbType.VarChar,1000)};
            parameters[0].Value = strArr[0];
            parameters[1].Value = strArr[1];
            parameters[2].Value = strArr[2];

            DbHelperSQL.RunProcedure("DailyItem_Manage", parameters, out rowsAffected);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DailyItem ");
            strSql.Append(" where IiD=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,6)};
            parameters[0].Value = ID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,IiD,DatePart,DeviceType ");
            strSql.Append(" FROM DailyItem ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,IiD,DatePart,DeviceType ");
            strSql.Append(" FROM DailyItem ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion  成员方法
    }
}